package com.primestone.cim.client.business;
//
//import java.io.FileWriter;
//import java.io.IOException;
//import java.util.List;
//
//import org.supercsv.cellprocessor.Optional;
//import org.supercsv.cellprocessor.ift.CellProcessor;
//import org.supercsv.io.CsvBeanWriter;
//import org.supercsv.io.ICsvBeanWriter;
//import org.supercsv.io.dozer.CsvDozerBeanWriter;
//import org.supercsv.io.dozer.ICsvDozerBeanWriter;
//import org.supercsv.prefs.CsvPreference;
//
///**
// * 
// * @author cesar.mateus
// * Jul 3, 2013 7:10:08 PM
// * CSVService.java
// * CIMClientApplication
// *
// */
public class CSVService {
//
//	/**
//	 * 
//	 */
//	private static final String TARGET_DIR = "D:\\Cesar\\zTmp\\";
//
//	/**
//	 * 
//	 * @param beans
//	 * @throws IOException 
//	 */
//	public static void writeCSVBean(List<CSVBean> beans) throws IOException{
//		ICsvBeanWriter beanWriter = null;
//		try {
//			beanWriter = new CsvBeanWriter(new FileWriter(TARGET_DIR + "result.csv"), CsvPreference.STANDARD_PREFERENCE);
//
//			// the header elements are used to map the bean values to each column (names must match)
//			final String[] header = new String[] { 
//					"ticket", "idBlock", "isLastBlock", "oldBlock", "idDevice", "idSocket", "varType", "meterReadings"};
//			final CellProcessor[] processors = getProcessors();
//
//			// write the header
//			beanWriter.writeHeader(header);
//
//			// write the beans
//			for( final CSVBean bean : beans ) {
//				beanWriter.write(bean, header, processors);
//			}
//
//		}
//		finally {
//			if( beanWriter != null ) {
//				beanWriter.close();
//			}
//		}
//	}
//
//	private static final String[] FIELD_MAPPING = new String[] { 
//		"ticket", "idBlock", "isLastBlock", "oldBlock", "idDevice", "idSocket", "varType",
//		"meterReadings.meterReading", // indexed (first element) + deep mapping
//		"meterReadings.readingType"
//	};
//
//	public static void writeDozerCsvBean(List<CSVBean> beans) throws Exception {
//
//		final CellProcessor[] processors = new CellProcessor[] {
//				new Optional(),     // age
//				new Optional(),  // consent
//				new Optional(),          // questionNo 1
//				new Optional(),         // answer 1
//				new Optional(),          // questionNo 2
//				new Optional(),         // answer 2
//				new Optional(),          // questionNo 3
//				new Optional(),          // questionNo 3
//				new Optional() };       // answer 4
//
//		// create the survey responses to write
//		/*SurveyResponse response1 = new SurveyResponse(18, true, Arrays.asList(new Answer(1, "Twelve"), new Answer(2,
//				"Albert Einstein"), new Answer(3, "Big Bang Theory")));
//		SurveyResponse response2 = new SurveyResponse(0, true, Arrays.asList(new Answer(1, "Thirteen"), new Answer(2,
//				"Nikola Tesla"), new Answer(3, "Stargate")));
//		SurveyResponse response3 = new SurveyResponse(42, false, Arrays.asList(new Answer(1, null), new Answer(2,
//				"Carl Sagan"), new Answer(3, "Star Wars")));
//		final List<SurveyResponse> surveyResponses = Arrays.asList(response1, response2, response3);*/
//
//		ICsvDozerBeanWriter beanWriter = null;
//		try {
//			beanWriter = new CsvDozerBeanWriter(new FileWriter(TARGET_DIR + "result.csv"),
//					CsvPreference.STANDARD_PREFERENCE);
//
//			// configure the mapping from the fields to the CSV columns
//			beanWriter.configureBeanMapping(CSVBean.class, FIELD_MAPPING);
//
//			// write the header
//			beanWriter.writeHeader("ticket", "idBlock", "isLastBlock", "oldBlock", "idDevice", "idSocket", "varType", "meterReading", "readingType");
//
//			// write the beans
//			for( final CSVBean bean : beans ) {
//				beanWriter.write(bean, processors);
//			}
//
//		}
//		finally {
//			if( beanWriter != null ) {
//				beanWriter.close();
//			}
//		}
//	}
//
//
//	/**
//	 * Sets up the processors used for the examples. There are 10 CSV columns, so 10 processors are defined. All values
//	 * are converted to Strings before writing (there's no need to convert them), and null values will be written as
//	 * empty columns (no need to convert them to "").
//	 * 
//	 * @return the cell processors
//	 */
//	private static CellProcessor[] getProcessors() {
//
//		final CellProcessor[] processors = new CellProcessor[] { 
//				new Optional(), // ticket
//				new Optional(), // idBlock
//				new Optional(), // isLastBlock
//				new Optional(), // oldBlock
//				new Optional(), // idDevice
//				new Optional(), // idSocket
//				new Optional(), // varType
//				new Optional() // mr
//				//				new Optional(), // timestamp
//				//				new Optional(), // value
//		};
//
//		return processors;
//	}
//
}